var dependencies = ['oc.lazyLoad', 'ngResource', 'fs.router', 'fs.constant', 'fs.storage', 'fs.ajax', 'fs.date', 'fs.modal', 'fs.layout', 'fs.menu'];
// 'ngAnimate',
angular.module('fs.waf', dependencies).run(main);

main.$inject = ['$rootScope', 'storageService'];

function main($rootScope, storageService) {
  // $rootScope.getBizDate = function() {
  //   return $rootScope.site.bizDate;
  // };

  // if (!angular.uppercase) {
  //   angular.uppercase = angular.$$uppercase;
  // }

  $rootScope.getBizDate = function() {
    // TODO $rootScope.site ?
    // return $rootScope.site.eodDate;
    return storageService.getSiteInfo() ? storageService.getSiteInfo().bizDate : new Date();
  };

  $rootScope.stopEventPropagation = function($event) {
    $event.preventDefault();
    $event.stopPropagation();
  };

  $rootScope.disableUnloadCheck = function() {
    delete $rootScope._isUnloadCheck;
    $window.onbeforeunload = null;
  };

  $rootScope.initFormState = function(scope, formDataKey, formName) {
    if ($rootScope._formName && $rootScope._formName != formName) {
      return;
    }
    $rootScope._formName = formName;
    if (formDataKey.indexOf('.searchCriteria') >= 0 || !scope.fsGridLayoutController || !scope.fsGridLayoutController.fsConfig) {
      return;
    }
    $rootScope._isUnloadCheck = true;
    $rootScope._formScope = $rootScope._formScope || {};
    $rootScope._formScope[formDataKey] = scope;
    $rootScope._formDataKey = $rootScope._formDataKey || [];
    $rootScope._formDataKey.push(formDataKey);
    $rootScope._formFields = $rootScope._formFields || [];
    $rootScope._formFields[formDataKey] = $rootScope._formFields[formDataKey] || {};
    $rootScope._formFields[formDataKey] = angular.merge($rootScope._formFields[formDataKey], getPageFormFields(scope.fsGridLayoutController.fsConfig));
    $rootScope._formDataHashCode = $rootScope._formDataHashCode || {};
    $rootScope._formDataHashCode[formDataKey] = commonService.hash(getPageFormData(scope.$eval(formDataKey), $rootScope._formFields[formDataKey]));
    $window.onbeforeunload = isFormChanged;
  };
}
